﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ControlLib
{
    public partial class THMonitor : UserControl
    {
        public THMonitor()
        {
            InitializeComponent();
        }

        private string titleName;

        public string TitleName
        {
            get { return titleName; }
            set { titleName = value; }
        }

        private byte deviceId = 1;
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("设置或显示该模块的站地址")]

        public byte Devided
        {
            get { return deviceId; }
            set {
                deviceId = value;
                this.gb_Device.Text = $"温湿度模块{deviceId}";
            }
        }

        private string humidity="0.0";
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("显示该模块的湿度值")]

        public string Humidity
        {
            get { return humidity; }
            set
            {
                if(value != humidity)
                {
                    humidity = value;
                    if(this.lbl_Humidity.InvokeRequired)
                    {
                        this.lbl_Humidity.Invoke(new Action(() =>
                        {
                            this.lbl_Humidity.Text = humidity;
                        }));
                    }
                    else
                    {
                        this.lbl_Humidity.Text = humidity;
                    }
                }
            }
        }

        private string temp = "0.0";
        [Browsable(true)]
        [Category("自定义属性")]
        [Description("显示该模块的湿度值")]

        public string Temp
        {
            get { return temp; }
            set
            {
                if (value != temp)
                {
                    temp = value;
                    if (this.lbl_Temp.InvokeRequired)
                    {
                        this.lbl_Temp.Invoke(new Action(() =>
                        {
                            this.lbl_Temp.Text = temp;
                        }));
                    }
                    else
                    {
                        this.lbl_Temp.Text = Temp;
                    }
                }
            }
        }
    }
}
